{extend name="public:base" /}


{block name="css"}
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css"/>
<link rel="stylesheet" type="text/css" href="__ADMIN__/css/style.css">{/block}

{block name="content"}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form method="post">
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">名称</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="name" placeholder="请输入名称" value="{$info.name}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">电话</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="mobile" placeholder="请输入电话" value="{$info.mobile}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row"><label class="col-sm-1 col-form-label">封面图</label>
                                <div class="col-sm-6">
                                    <input type="file" id="img_file" accept="image/*" style="display: none">
                                    <input type="hidden" class="hidden_value" name="img" id="img" value="{$info['img']|default=''}"/>
                                    <div class="btn btn-w-m btn-primary" onclick="uploadImage('img_file', 'img', 'form-uploaded-box-single', false, 1)">原图上传</div>
                                    <div class="btn btn-w-m btn-primary" onclick="openCrop('form-uploaded-box-single', 1)">裁剪上传</div>

                                    <div class="form-uploaded-box" id="form-uploaded-box-single" style="width: 140px">
                                        {if $info.img}
                                        <div class="form-uploaded-img-box">
                                            <img class="form-uploaded-box-img" src="{:getPicture($info.img)}" data-id="{$info.img}">
                                            <i class="form-uploaded-img-preview iconfont icon-yulan" onclick="previewImg(this, 'form-uploaded-img-preview', 'form-uploaded-box-single')"></i>
                                            <i class="form-uploaded-img-del iconfont icon-close" onclick="delImage(this, 'cropper_uploaded_img_ids', 'cropper_uploaded_img_paths', 'form-')"></i>
                                        </div>
                                        {/if}
                                    </div>
                                </div>

                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <!--<div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">省市区</label>
                                <div class="col-sm-3">
                                    <select class="form-control province" name="province_id">
                                        <option value="0">请选择</option>
                                        {volist name="region_list" id="vo"}
                                        <option value="{$vo.id}" {$info.province_id== $vo.id ?
                                        'selected' : ''}>{$vo.name}</option>
                                        {/volist}
                                    </select>
                                </div>
                                <div class="col-sm-3">
                                    <select class="form-control city" name="city_id">
                                        <option value="0">请选择</option>
                                    </select>
                                </div>
                                <div class="col-sm-3">
                                    <select class="form-control area" name="area_id">
                                        <option value="0">请选择</option>
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>-->

                        <!-- 地图开发文档：https://lbs.qq.com/webApi/component/componentGuide/componentPicker -->
                        <div class="box-item">
                            <div class="form-group row layui-form">
                                <label class="col-lg-1 col-form-label">门店定位（请勾选下方列表地址之后再进行提交）</label>
                                <div class="col-lg-10">
                                    <div style="width: 900px;height: 700px">
                                        <iframe id="mapPage" width="100%" height="100%" frameborder=0
                                                src="{$map_url}">
                                        </iframe>
                                    </div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">详细地址</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control address" name="address" placeholder="请输入详细地址" value="{$info.address}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <input type="hidden" name="id" value="{$info['id']}">
                        <input type="hidden" class="lat" name="lat" value="{$info.lat}">
                        <input type="hidden" class="lng" name="lng" value="{$info.lng}">

                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button type="button" class="btn btn-w-m btn-default back-page">返回</button>
                                <button type="button" class="btn btn-w-m btn-primary ajax-post">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{include file="public/cropper-img-mask" cropper_uploaded_img_ids="cropper_uploaded_img_ids" cropper_uploaded_img_paths="cropper_uploaded_img_paths" crop_preview_box="crop-preview-box" /}

{include file="public/preview-img-mask" swiper-id="cropper-preview" /}

{/block}

{block name='js'}
<script src="__STATIC__/layui/layui.js"></script>
<script>
    window.addEventListener('message', function (event) {
        if(event.data){
            var {lat, lng} = event.data.latlng;
            var {poiaddress, poiname} = event.data;
            $('.lat').val(lat)
            $('.lng').val(lng)
            $('.address').val(poiaddress + poiname)
        }
    }, false);

</script>

<script>
    /*var region_list = {$region_list_json};
    var city_list;

    $(function () {
        var id = "{:input('id')}";
        var province_id = "{$info.province_id}";
        var city_id = "{$info.city_id}";
        var area_id = "{$info.area_id}";

        if (id > 0) {
            for (let i in region_list) {
                if (province_id == region_list[i].id) {
                    city_list = region_list[i].city_list;
                    break;
                }
            }
            renderOption(city_list, 'city', city_id);

            for (let i in city_list) {
                if (city_id == city_list[i].id) {
                    area_list = city_list[i].area_list;
                    break;
                }
            }
            renderOption(area_list, 'area', area_id);
        }
    })

    $('.province').change(function () {
        var id = $(this).val();

        for (let i in region_list) {
            if (id == region_list[i].id) {
                city_list = region_list[i].city_list;
                break;
            }
        }

        renderOption(city_list, 'city');
    })

    $('.city').change(function () {
        var id = $(this).val();

        for (let i in city_list) {
            if (id == city_list[i].id) {
                var area_list = city_list[i].area_list;
                break;
            }
        }
        renderOption(area_list, 'area');
    })

    function renderOption(region_list, class_name, id = 0) {
        var option = '<option value="0">请选择</option>';
        var selected = '';
        for (let i in region_list) {
            selected = id == region_list[i].id ? 'selected' : '';
            option += '<option ' + selected + ' value="' + region_list[i].id + '">' + region_list[i].name + '</option>';
        }
        $('.' + class_name).html(option);
    }*/

</script>

{/block}
